package com.homegoods.home.item;

import com.alibaba.android.arouter.launcher.ARouter;
import com.homegoods.home.R;
import com.homegoods.home.model.HotSearchKeyWordModel;
import com.homegoods.home.model.SearchListModel;
import com.homegoods.home.utils.SearchHistoryUtil;
import com.homegoods.aroutercomment.ARouterPath;
import com.kedll.library.adapter.MultiTypeAdapter;
import com.kedll.library.mvp.BaseItem;


/**
 * @author Lxl
 * @date 2017/5/8
 */

public class SearchListItem extends BaseItem {

    private HotSearchKeyWordModel itemModel;
    private SearchListModel searchListModel;

    public SearchListItem(final HotSearchKeyWordModel itemModel, SearchListModel searchListModel, MultiTypeAdapter adapter) {
        super(null);
        this.itemModel = itemModel;
        this.searchListModel = searchListModel;
        setOnClickListener(view -> {
            SearchListModel searchListModel1 = new SearchListModel();
            searchListModel1.setTitle("" + getTitle());
            searchListModel1.setId(SearchHistoryUtil.getSearchList().size());
            SearchHistoryUtil.saveSearchList(searchListModel1);
            //跳转到搜索结果页面
            ARouter.getInstance()
                    .build(ARouterPath.PATH_SEARCH_RESULT)
                    .withString("searchContent", getTitle())
                    .navigation();
        });
    }

    public String getTitle() {
        return itemModel == null ? searchListModel.getTitle() : itemModel.getTitle();
    }

    @Override
    public int getLayout() {
        return R.layout.home_item_search_layout;
    }

}